package com.ihr360.payroll.model.dto.attendance.rule.sickleave;

import com.ihr360.payroll.model.dto.attendance.supperclass.AbstractCalcAttendanceRule;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import java.io.Serializable;

/** 病假规则 */
@Entity
@TypeDefs({
        @TypeDef(name = "json", typeClass = JsonStringType.class),
        @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class SickLeaveRule extends AbstractCalcAttendanceRule {


    private Boolean advancedDeductionEnable;

    //这里只需要一个配置就可以了，不需要两个。
    //单独添加一个字段来设置类型
    @Column(columnDefinition = "varchar(20)")
    @Enumerated(EnumType.STRING)
    private DeductionByType deductionBy;
    /**
     * 扣除比例配置
     */
    @Column(columnDefinition = "varchar(1000)")
    @Type(type = "json")
    private DeductConfigWrapper DeductConfig;


    public DeductConfigWrapper getDeductConfig() {
        return DeductConfig;
    }

    public void setDeductConfig(DeductConfigWrapper deductConfig) {
        DeductConfig = deductConfig;
    }

    public DeductionByType getDeductionBy() {
        return deductionBy;
    }

    public void setDeductionBy(DeductionByType deductionBy) {
        this.deductionBy = deductionBy;
    }

    public Boolean getAdvancedDeductionEnable() {
        return advancedDeductionEnable;
    }

    public void setAdvancedDeductionEnable(Boolean advancedDeductionEnable) {
        this.advancedDeductionEnable = advancedDeductionEnable;
    }

    public static final class DeductConfigWrapper implements Serializable {
        private static final long serialVersionUID = -5087647360663298337L;

        private Integer[] years;

        private Config[] configs;

        public DeductConfigWrapper() {
        }

        public DeductConfigWrapper(Integer[] years, Config[] configs) {
            this.years = years;
            this.configs = configs;
        }

        public Integer[] getYears() {
            return years;
        }

        public void setYears(Integer[] years) {
            this.years = years;
        }

        public Config[] getConfigs() {
            return configs;
        }

        public void setConfigs(Config[] configs) {
            this.configs = configs;
        }

        public static final class Config implements Serializable  {
            private static final long serialVersionUID = -6090669721108573950L;
            private Integer[] days;

            private Integer[] ratios;

            public Integer[] getDays() {
                return days;
            }

            public void setDays(Integer[] days) {
                this.days = days;
            }

            public Integer[] getRatios() {
                return ratios;
            }

            public void setRatios(Integer[] ratios) {
                this.ratios = ratios;
            }
        }

    }
}